﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
//using ESRI.ArcGIS.TOCControl;

namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：关闭所有图层
    /// 作者：
    /// 编写日期：2009-03-25
    /// </summary>
    internal class AllLayersUnVisible : BaseCommand
    {
        IApplication m_Application = null;
        public AllLayersUnVisible()
        {
            base.m_caption = "关闭所有图层";
            base.m_toolTip = base.Caption;
        }
        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;
        }

        public override void OnClick()
        {
            if ( (m_Application as IFramework).TOCControl.CustomProperty is IGroupLayer)
            {
                ICompositeLayer groupLyr = (m_Application as IFramework).TOCControl.CustomProperty as ICompositeLayer;
                for (int i = 0; i < groupLyr.Count; i++)
                {
                    groupLyr.Layer[i].Visible = false;
                }



            }
            else
            {
                for (int i = 0; i < (m_Application.Document as IMxDocument).ActiveView.FocusMap.LayerCount; i++)
                {
                    (m_Application.Document as IMxDocument).ActiveView.FocusMap.get_Layer(i).Visible = false;
                }
            }
           
            (m_Application as IFramework).TOCControl.Update();
            (m_Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, (m_Application.Document as IMxDocument).ActiveView.Extent);


        }
        public override bool Enabled
        {
            get
            {
                return (m_Application as IFramework).IsMapCtrlactive;
            }
        }

        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;

                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
}
